package com.fast.modules.acd.service.impl.jvm;

import java.util.LinkedList;
import java.util.List;

import com.fast.modules.acd.entity.Node;
import com.fast.modules.acd.service.QueueStorageService;

/**
 * 队列的默认存储机制，存储到JVM的static list中
 * 
 * @author yaoyuquan
 *
 */
public class QueueStorageServiceJVMImpl implements QueueStorageService {
	
	
	/**
	 * 排队的信息list
	 */
	static LinkedList<Node> list = new LinkedList<Node>();

	@Override
	public List<Node> list() {
		return list;
	}

	/**
	 * Retrieves and removes the first element of this list, or returns null if this list is empty.
	 * 获取并删除第一个元素，如果list为空，返回null
	 */
	@Override
	public Node pop() {
		return list.pollFirst();
	}

	@Override
	public void push(Node node) {
		list.push(node);
	}

	@Override
	public int addLast(Node node) {
		list.addLast(node);
		return list.size();
	}

	@Override
	public boolean remove(Node node) {
		return list.remove(node);
	}
}
